# 导包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 创建浏览器对象
driver = webdriver.Firefox()
# 打开注册页面
url = 'file:///C:/Users/TEACHER/Desktop/NSD2405/html/registerA.html'
driver.get(url)

# 通过XPATH定位密码框，并输入值
# / 绝对路径 子元素
# // 相对路径 后代元素
# 遇到多个子元素，通过索引区分位置，默认是第1个
# 索引是从1开始
# 可以结合元素属性
#  * 所有元素
# username = driver.find_element(By.XPATH, '/html/body/form/div/fieldset/p[@id="p1"]/input')
# username = driver.find_element(By.XPATH, '//p[@id="p1"]/input')
# username = driver.find_element(By.XPATH, '//input[@name="userA" and @id="userA"]')
username = driver.find_element(By.XPATH, '//*[@id="userA"]')
username.send_keys('admin')
driver.find_element(By.XPATH, '/html/body/form/div/fieldset/p[2]/input').send_keys('888999')

# 停顿3秒钟，关闭浏览器驱动
sleep(3)
driver.quit()